function WavefrontLoader(xmlref)
{
	this.xmlref = xmlref;
	this.data = new Object();

	this.nvertices = 0;
	this.voffset = 0;
	this.toffset = 0;
}

WavefrontLoader.prototype.createArrays = function()
{
	var filedata = this.xmlref.responseText;


	var vlines = filedata.match(/^v [ \-\.0-9]+$/igm);
	var vcoord = new Array();


	for(var i=0; i<vlines.length; i++)
	{
		var values = vlines[i].substr(2, vlines[i].length-2);
		var coordinates = values.split(" ");

		vcoord.push([
			parseFloat(coordinates[0]),
			parseFloat(coordinates[1]),
			parseFloat(coordinates[2])
		]);		
	}


	var uvlines = filedata.match(/^vt [ \.0-9]+$/igm);
	var tcoord = new Array();

	for(var i=0; i<uvlines.length; i++)
	{
		var values = uvlines[i].substr(3, uvlines[i].length-3);
		var coordinates = values.split(" ");

		tcoord.push([
			parseFloat(coordinates[0]),
			parseFloat(coordinates[1])
		]);
	}


	var flines = filedata.match(/^f [ \/0-9]+$/igm);

	this.nvertices = flines.length*3;
	this.data.vertices = new Float32Array(this.nvertices*3);
	this.data.uv = new Float32Array(this.nvertices*2);

	var index = new Object();

	for(var i=0; i<flines.length; i++)
	{
		var offset = i*3;
		var values = flines[i].substr(2, flines[i].length-2);

		var array = values.split(" ");
		index.a = array[0].split("/");
		index.b = array[1].split("/");
		index.c = array[2].split("/");

		this.addCoordinates(parseInt(index.a[0])-1, vcoord, 'v');
		this.addCoordinates(parseInt(index.b[0])-1, vcoord, 'v');
		this.addCoordinates(parseInt(index.c[0])-1, vcoord, 'v');

		this.addCoordinates(parseInt(index.a[1])-1, tcoord, 't');
		this.addCoordinates(parseInt(index.b[1])-1, tcoord, 't');
		this.addCoordinates(parseInt(index.c[1])-1, tcoord, 't');
	}


	vcoord = null;
	tcoord = null;
	index = null;
}

WavefrontLoader.prototype.addCoordinates = function(id, data, type)
{
	if(type == 'v')
	{
		this.data.vertices[this.voffset+0] = data[id][0];
		this.data.vertices[this.voffset+1] = data[id][1];
		this.data.vertices[this.voffset+2] = data[id][2];
		this.voffset += 3;
	}
	else if(type == 't')
	{
		this.data.uv[this.toffset+0] = data[id][0];
		this.data.uv[this.toffset+1] = data[id][1];
		this.toffset += 2;
	}
}

WavefrontLoader.prototype.initBuffers = function()
{
	this.createArrays();

	var glBuffers = new Object();
	glBuffers.vertices = gl.createBuffer();
	glBuffers.uv = gl.createBuffer();

	gl.bindBuffer(gl.ARRAY_BUFFER, glBuffers.vertices);
	gl.bufferData(gl.ARRAY_BUFFER, this.data.vertices, gl.STATIC_DRAW);

	gl.bindBuffer(gl.ARRAY_BUFFER, glBuffers.uv);
	gl.bufferData(gl.ARRAY_BUFFER, this.data.uv, gl.STATIC_DRAW);

	return glBuffers;
}
